﻿// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Globalization;
using System.Reflection;
using Microsoft.Internal;
using System.ComponentModel.Composition.ReflectionModel;

namespace System.ComponentModel.Composition.AttributedModel
{
    internal class AttributedParameterImportDefinition : AttributedImportDefinition
    {
        private readonly ReflectionParameter _parameter;

        public AttributedParameterImportDefinition(ParameterInfo parameter)
            : this(new ReflectionParameter(parameter))
        {
        }

        private AttributedParameterImportDefinition(ReflectionParameter parameter)
            : base(parameter.ReturnType, parameter.UnderlyingParameter)
        {
            this._parameter = parameter;
        }

        public override bool IsRecomposable
        {
            // Currently only used for constructor parameters so it is always non-recomposable
            get { return false; }
        }

        public override bool IsPrerequisite
        {
            // Currently only used for constructor parameters so it is always a prerequisite
            get { return true; }
        }

        public ParameterInfo Parameter
        {
            get { return _parameter.UnderlyingParameter; }
        }

        public override string ToString()
        {
            return string.Format(
                CultureInfo.InvariantCulture,
                "ContractName={0},ParameterType={1},ParameterName={2}",
                this.ContractName,
                this._parameter.ReturnType.Name,
                this._parameter.Name);
        }

        public override ImportingItem ToImportingItem()
        {
            return new ImportingParameter(this, this._parameter);
        }
    }
}
